package cn.intertion.scaner;

import cn.intertion.model.wxObj;
import cn.intertion.service.WXScanners;
import cn.intertion.service.WxToken;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
@EnableAsync
public class WXScaner {

    @Autowired
    private WXScanners wxScanners;
    @Autowired
    private WxToken wxToken;

    @Async
    @Scheduled(cron = "0 */2 * * * ?")
    public void NotifyUserByWX() throws Exception {
        if (wxObj.accessToken.equals("")) {
            wxToken.setWXAccessToken();
        } else {
            long l = wxObj.tokenDate;
            long ll = System.currentTimeMillis() - l;
            if (ll > ((long)30 * 60 * 1000) && l != 0) {
                wxToken.setWXAccessToken();
            }
            wxScanners.notifyUsers();
        }
    }




}
